#include "Rook.h"
#include "../Game/Engine.h"
#include "../Board/Chessboard.h"
#include "../Board/Square.h"

namespace Core
{
	Rook::Rook(Player * player, Square * square)
		:Piece(player, square)
	{
	}


	Rook::~Rook(void)
	{
	}

	std::string Rook::name() const { return "Rook"; }
	ChType Rook::type() const { return ChType::ChRook; }

	//Move * Rook::canMove(Square * dst)
	//{
	//	Move * mv = Move::createMove(this, dst);

	//	return mv;
	//}


	void Rook::updateValidMoves()
	{
		int r = this->square()->row();
		int c = this->square()->column();
		
		considerForValidMoves(r+1, c);
		considerForValidMoves(r-1, c);
		considerForValidMoves(r, c+1);
		considerForValidMoves(r, c-1);
	}

	void Rook::considerForValidMoves(int r2, int c2)
	{
		const Chessboard * brd = Engine::instance()->chessboard();
		try
		{
			 Piece * p = brd->findPieceDirect(square()->row(), square()->column(), r2, c2, true, &_validMoves); // might throw exception
		}
		catch(...) { }
	}

}
